package com.alumni_circle.mapper.gossip;

import com.alumni_circle.entity.gossip.Gossip;
import com.alumni_circle.entity.gossip.VO.GossipViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @author 龙小虬
 * @since 2020-07-06 22:11
 */
public interface GossipMapper extends BaseMapper<Gossip> {

    @Select("SELECT gossip.id,gossip.title,gossip.content,gossip.picture,gossip.create_time,gossip.views,gossip.praise,gossip.comments,user.`name`,user.`icon`\n" +
            "FROM user_gossip,user,gossip\n" +
            "WHERE user.id = user_gossip.user_id and gossip.state = '0' and user_gossip.gossip_id = gossip.id\n" +
            "ORDER BY create_time DESC")
    List<GossipViewVO> selectListGossip();

    @Select("SELECT gossip.id,gossip.title,gossip.content,gossip.picture,gossip.create_time,gossip.views,gossip.praise,gossip.comments,user.`name`,user.`icon`\n" +
            "FROM user_gossip,user,gossip\n" +
            "WHERE user.id = user_gossip.user_id and gossip.state = '0' and user_gossip.gossip_id = gossip.id and user.id = #{id}\n" +
            "ORDER BY create_time DESC")
    List<GossipViewVO> selectMyListGossip(@Param("id") String id);

    @Select("SELECT gossip.id,gossip.title,gossip.content,gossip.picture,gossip.create_time,gossip.views,gossip.praise,gossip.comments,user.`name`,user.`icon`\n" +
            "FROM user_gossip,user,gossip\n" +
            "WHERE user.id = user_gossip.user_id and gossip.state = '0' and user_gossip.gossip_id = gossip.id and user.id = #{id}\n" +
            "and (gossip.title like concat ('%',#{search},'%') or gossip.content like concat('%',#{search},'%')) \n"+
            "ORDER BY create_time DESC")
    List<GossipViewVO> searchMyListGossip(@Param("id") String id,@Param("search")String search);


    @Select("update gossip set comments=comments+1 where id = #{id}\n")
    void updateComments(@Param("id")String id);

    @Select("update gossip set views=views+1 where id = #{id}\n")
    void updateGossipViews(@Param("id")String id);

    @Select("update gossip set praise=praise+1 where id = #{id}\n")
    void updateGossipPraise(@Param("id")String id);

}
